package com.translate.service.service.task;

import com.translate.commons.asynctask.AsyncTaskExecutor;
import com.translate.commons.utils.SpringContextHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 自定义的线程
 * 如果用springboot的线程就不用这个
 */
@Service
public class DemoService {

    @Resource
    private SpringContextHelper springContextHelper;
    @Resource
    private AsyncTaskExecutor asyncTaskExecutor;

    public void initData(String demof) {
        DemoTask task = new DemoTask(springContextHelper, demof);
        asyncTaskExecutor.push(task);
        asyncTaskExecutor.start();
    }

    public void method(String demof) throws Exception {
        System.out.println("开始做任务"+demof);
        long start = System.currentTimeMillis();
        Thread.sleep(10000);
        long end = System.currentTimeMillis();
        System.out.println("完成任务"+demof+"，耗时：" + (end - start) + "毫秒");
    }

}
